package com.nine.pesys.model.action;

import com.nine.pesys.base.BaseAction;
import com.nine.pesys.model.entity.Equipment;
import com.nine.pesys.model.entity.User;
import com.nine.pesys.util.annotation.Privilege;
import com.nine.pesys.util.common.PageData;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.*;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


/**
 * Created by L先森 on 2014/12/26.
 */
@Controller
@Scope("prototype")
@Namespace("/equipment")
@ParentPackage("my_struts")
@Results({
        @Result(name = "setEquipmentAttribute",location = "/front/home.jsp"),

        @Result(name = "bsEqList",location = "/admin/equipment/equipment_list.jsp"),
})
@Privilege
public class EquipmentAction extends BaseAction<Equipment> {

    @Action("/allEquipment")
    public String allEquipment() throws Exception{
        equipments = this.equipmentService.findAll();
        if (equipments!=null&&equipments.size()>0) {
            System.out.println(equipments.size()+"===="+pageNo+"====="+equipments);
            PageData<Equipment> eqPageData = new PageData<Equipment>(equipments.size(), pageNo, pageSize, equipments);
            if (pageNo>eqPageData.getTotalPageCount())
                pageNo = eqPageData.getTotalPageCount();
            equipments = this.equipmentService.getByPage(pageSize,pageNo);
            ActionContext.getContext().put("equipments",equipments);
            ActionContext.getContext().put("pageData",eqPageData);
        }
        return "bsEqList";
    }

    /**
     * 器材属性设置
     * @return
     * @throws Exception
     */
    @Privilege("super")
    @Action("/setEquipmentAttribute")
    public String setEquipmentAttribute() throws Exception{
        this.equipmentService.update(model);
        return "setEquipmentAttribute";
    }

}
